package cn.jbolt.admin.userconfig;

import cn.jbolt.core.api.JBoltApiBaseController;
import cn.jbolt.core.api.JBoltApiKit;
import cn.jbolt.core.api.httpmethod.JBoltHttpGet;
import cn.jbolt.core.api.httpmethod.JBoltHttpPost;
import cn.jbolt.core.cache.JBoltUserConfigCache;
import cn.jbolt.core.model.UserConfigKey;
import cn.jbolt.core.model.base.JBoltBaseModel;
import cn.jbolt.core.permission.UnCheck;
import cn.jbolt.core.service.base.JBoltBaseService;
import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.core.Path;
import com.jfinal.core.paragetter.Para;
import com.jfinal.plugin.activerecord.tx.Tx;

@UnCheck
@Path("/api/admin/userConfig")
public class UserConfigAdminController extends JBoltApiBaseController {
    @Inject
    UserConfigService service;

    @Override
    protected JBoltBaseService<? extends JBoltBaseModel<?>> getModelService() {
        return service;
    }

    /**
     * 获取用户配置
     * 指定一个key
     * 返回整个配置对象
     */
    @JBoltHttpGet
    public void index(@Para("key")String key){
        renderJBoltApiSuccessWithData(JBoltUserConfigCache.me.get(JBoltApiKit.getApiUserIdToLong(), key));
    }

    @Before(Tx.class)
    @JBoltHttpPost
    public void change(@Para("key")String configKey,@Para("theme")String configValue){
        renderJBoltApiRet(service.changeUserConfig(JBoltApiKit.getApiUserIdToLong(), configKey,configValue));
    }

}
